package com.zyz.G_常用类.包装类;

/**
 * @author: vick
 * @Date: 2025/3/18
 * @Description:
 * @version: 1.0
 */
public class Demo2 {
    public static void main(String[] args) {
        // x1 >= -128 && <= 127, 所以直接从缓存对象中获取，否则新建 Integer对象
        Integer x1 = 99;
        Integer y1 = 99;
        System.out.println(x1 == y1); //true  地址一样
        System.out.println(x1.equals(y1)); //true

        Integer x2 = 127;
        Integer y2 = 128;
        System.out.println(x2 == y2); // false

        //使用new创建了对象，所以地址不一样
        Integer x3 = new Integer(127);
        Integer y3 = new Integer(127);
        System.out.println(x3 == y3); //false
        System.out.println(x3.equals(y3)); //true

        // x4 > 127, 所不符合条件，直接新建 Integer对象
        Integer x4 = 128;
        Integer y4 = 128;
        System.out.println(x4 == y4);//false
        System.out.println(x4.equals(y4));//true


        Integer x5 = 128;
        Integer y5 = new Integer(128);
        System.out.println(x5 == y5);//false
        System.out.println(x5.equals(y5));//true
    }
}
